package com.ycsj.goldmedalnewconcept.activity;

import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.widget.ProgressBar;

import com.ycsj.goldmedalnewconcept.utils.MyWebViewClient;
import com.ycsj.goldmedalnewconcept.R;

@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
public class ClassThirdHorizontalActivity extends BaseJpStarActivity {

	private WebView mWebView;
	private ProgressBar mprogressBar;

	@SuppressLint("InlinedApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		getWindow().requestFeature(Window.FEATURE_PROGRESS);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_classthird_horizontal);
		
		mWebView = (WebView) findViewById(R.id.webview_player);
		 mprogressBar = (ProgressBar) findViewById(R.id.mProgress);
		 
		 
		 getWindow().addFlags(
				 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);

		if (getPhoneAndroidSDK() >= 14) {// 4.0需打开硬件加速
			getWindow().setFlags(0x1000000, 0x1000000);
		}
		initWebView();
	}

	@SuppressWarnings("deprecation")
	private void initWebView() {
		WebSettings settings = mWebView.getSettings();
		settings.setJavaScriptEnabled(true);
		settings.setJavaScriptCanOpenWindowsAutomatically(true);
		settings.setPluginState(PluginState.ON);
//		settings.setPluginsEnabled(true);
		settings.setAllowFileAccess(true);
		settings.setLoadWithOverviewMode(true);

		if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){  
			settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);  
	     } 
		
		mWebView.setWebViewClient(new MyWebViewClient(mprogressBar));
		mWebView.setWebChromeClient(new WebChromeClient() {
			@Override
			public void onProgressChanged(WebView view, int newProgress) {
				// TODO Auto-generated method stub
				// MainActivity.this.setProgress(newProgress * 100);
				mprogressBar.setProgress(newProgress);
			}
		});
		
		String URL = getIntent().getStringExtra("URL");
		
		mWebView.loadUrl(URL);
		
	}
	
	public static int getPhoneAndroidSDK() {
		// TODO Auto-generated method stub
		int version = 0;
		try {
			version = Integer.valueOf(Build.VERSION.SDK);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		return version;
	}
	
	@Override
	public void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		
		mWebView.reload();
	}
}
